import type { phoneInfoType } from '@/types/component'
import { defineStore } from 'pinia'
import { ref } from 'vue'

export const usePhoneStore = defineStore(
  'phone',
  () => {
    /**
     * @description phoneInfo 手机信息
     */
    const phoneInfo = ref<phoneInfoType | null>(null)
    /**
     *
     * @description setPhoneInfo 修改手机信息方法
     */
    const setPhoneInfo = (val: phoneInfoType) => {
      phoneInfo.value = val
    }
    /**
     * @description deletePhoneInfo 删除手机信息方法
     */
    const deletePhoneInfo = () => {
      phoneInfo.value = null
    }
    return {
      phoneInfo,
      setPhoneInfo,
      deletePhoneInfo,
    }
  },
  {
    // 数据持久化
    persist: {
      storage: {
        setItem(key, value) {
          uni.setStorageSync(key, value)
        },
        getItem(key) {
          return uni.getStorageSync(key)
        },
      },
    },
  },
)
